package tool;

import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Properties;

import dataStore.UserDataStoreApiInterface;

public class GetMasterApi {

	/*
	 * lookup mastetDataStortApi
	 */
	public	static UserDataStoreApiInterface get_masterDSApi(
			Properties userProper) throws NumberFormatException,
			RemoteException, NotBoundException {
//		Short.parseShort(userProper.getProperty("masterDataStoreUserPort")
		try {
			final Registry registry = LocateRegistry.getRegistry(
					userProper.getProperty("masterAdress"),
					Short.parseShort(userProper.getProperty("rmi_masterDataStoreUserPort")));
			final UserDataStoreApiInterface masterDSApi = (UserDataStoreApiInterface) registry
					.lookup("userDataStoreApi");
			return masterDSApi;
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
			System.out.println("userDataMaster registory remote exception");
			System.out.println("userDataMaster registory  failed");
			return null;
		} catch (NotBoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
			System.out.println("userDataMaster registory not bound exception");	
			System.out.println("userDataMaster registory  failed");
			return null;
		}
	}
	

	
}
